package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChargingStation;
import com.ruoyi.system.service.IChargingStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电站信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/system/station")
public class ChargingStationController extends BaseController
{
    @Autowired
    private IChargingStationService chargingStationService;

    /**
     * 查询充电站信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargingStation chargingStation)
    {
        startPage();
        List<ChargingStation> list = chargingStationService.selectChargingStationList(chargingStation);
        return getDataTable(list);
    }

    /**
     * 导出充电站信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:station:export')")
    @Log(title = "充电站信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargingStation chargingStation)
    {
        List<ChargingStation> list = chargingStationService.selectChargingStationList(chargingStation);
        ExcelUtil<ChargingStation> util = new ExcelUtil<ChargingStation>(ChargingStation.class);
        util.exportExcel(response, list, "充电站信息数据");
    }

    /**
     * 获取充电站信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:station:query')")
    @GetMapping(value = "/{csId}")
    public AjaxResult getInfo(@PathVariable("csId") Integer csId)
    {
        return success(chargingStationService.selectChargingStationByCsId(csId));
    }

    /**
     * 新增充电站信息
     */
    @PreAuthorize("@ss.hasPermi('system:station:add')")
    @Log(title = "充电站信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargingStation chargingStation)
    {
        return toAjax(chargingStationService.insertChargingStation(chargingStation));
    }

    /**
     * 修改充电站信息
     */
    @PreAuthorize("@ss.hasPermi('system:station:edit')")
    @Log(title = "充电站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargingStation chargingStation)
    {
        return toAjax(chargingStationService.updateChargingStation(chargingStation));
    }

    /**
     * 删除充电站信息
     */
    @PreAuthorize("@ss.hasPermi('system:station:remove')")
    @Log(title = "充电站信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{csIds}")
    public AjaxResult remove(@PathVariable Integer[] csIds)
    {
        return toAjax(chargingStationService.deleteChargingStationByCsIds(csIds));
    }

    /**
     * 查询今日每个站的充电度数
     */
    @GetMapping("/selectTodayStationCharge")
    public List<Map<String,Object>> selectTodayStationCharge(){
        return chargingStationService.selectTodayStationCharge();
    };

    /**
     * 查询充电站信息列表
     *
     * @param chargingStation 充电站信息
     * @return 充电站信息集合
     */
    @GetMapping("/list2")
    public List<Map<String,Object>> selectChargingStationList2(ChargingStation chargingStation){
        return chargingStationService.selectChargingStationList2(chargingStation);
    };

//    /**
//     * 查询充电站信息列表 根据用户id
//     *
//     * @param csSysUserId 用户id集合
//     * @return 充电站信息集合
//     */
//    @GetMapping("/list3")
//    public List<Map<String,Object>> selectChargingStationList3(List<Integer> csSysUserId){
//        return chargingStationService.selectChargingStationList3(csSysUserId);
//    };
//
//    /**
//     * 查询用户id 根据用户昵称
//     *
//     * @param nickName 用户昵称
//     * @return 用户id集合
//     */
//    @GetMapping("/selectUserIdByNickName")
//    public List<Integer> selectUserIdByNickName(String nickName){
//        return chargingStationService.selectUserIdByNickName(nickName);
//    };
}
